Open Tabs
Kernels
Python 3 (ipykernel)
- 02_bar_plot
Python 3 (ipykernel)
- session_day2
Python 3 (ipykernel)
- indexing and data structure
Python 3 (ipykernel)
- test_jupyter_notebook
Python 3 (ipykernel)
- 03_boxplot
Language servers
Terminals
06_array
- 1D array
- 2D array
- in 2D array when we talk about the axis first we include the column and then row e.g(2,4) in this 2 is the column and 4 is the row
- 3D array
/Desktop/data_viz/
Name
...
Last Modified
File Size
- 01_line_plotyesterday310.4 KB
- 02_bar_plotyesterday266.8 KB
- 03_boxplot22 hours ago239 KB
- 04_otherplots8 hours ago228.1 KB
- 05_interactive5 hours ago3.7 MB
- 06_array43 seconds ago14.8 KB
Kernel status: Idle
[ ]:
[10]:
# my first program
print(2+3)
print("hello world")
print("asad and fareeha")
5 hello world asad and fareeha
[ ]:
**02-operators**
[12]:
#operators function
print(2+3)
print(3-1)
print(3*2)
print(4/2) #single division given the value in float
print(13%2)
print(6//2) #double divide goven the value in int type
#using the power function by using double sterric
print(2**3)
#now we form the equation
print(3**2/2*3/3+6-4)
5 2 6 2.0 1 3 8 6.5
*now we see sequence with which the code is running
PEDMAS
paranthesis exponenet division multiplication divsion addition subtraction
this process is running according left_to_right*
now we see sequence with which the code is running PEDMAS paranthesis exponenet division multiplication divsion addition subtraction this process is running according left_to_right
**03-string**
03-string
[15]:
print("hello world")
print("python with asad")
print("asad is learning python from ammar")
#we can write the string in the sigle ,double or tripple quotes
print('hi')
print("helloo")
print('''how are you''')
#spaces are effect inside the string there is no effect of space inside the string
print("what's up")
hello world python with asad asad is learning python from ammar hi helloo how are you what's up
Kernel status: Idle
[2]:
# make a string
a="asad ibadat"
a
[2]:
'asad ibadat'
[4]:
a
[4]:
'asad ibadat'
[8]:
a[0]
[8]:
'a'
[12]:
a[10]
[12]:
't'
[14]:
a[5]
[14]:
'i'
[16]:
a[2]
[16]:
'a'
[18]:
a[7]
[18]:
'a'
[20]:
a[9]
[20]:
'a'
[22]:
a[8]
[22]:
'd'
[26]:
b="fareeha"
b
[26]:
'fareeha'
[28]:
b[4]
[28]:
'e'
[30]:
b[6]
[30]:
'a'
[37]:
c="i am learning python by dr ammar"
c
[37]:
'i am learning python by dr ammar'
[41]:
c[15]
[41]:
'y'
[43]:
c[6]
[43]:
'e'
[45]:
c[7]
[45]:
'a'
[59]:
# last index is exclusive
a[0:10]
[59]:
'asad ibada'
[51]:
a[0:11]
[51]:
'asad ibadat'
[53]:
b[0:7]
[53]:
'fareeha'
[55]:
c[0:15]
[55]:
'i am learning p'
[57]:
c[0:17]
[57]:
'i am learning pyt'
[61]:
a[-5:1]
[61]:
''
[65]:
a[-2]
[65]:
'a'
[69]:
a[-1]
[69]:
't'
[71]:
a[-10]
[71]:
's'
[73]:
a[-6:-1]
[73]:
'ibada'
[33]:
len(b)
[33]:
7
[35]:
len(a)
[35]:
11
[47]:
len(c)
[47]:
32
# string methods
string methods¶
[77]:
food="biryani"
food
[77]:
'biryani'
[79]:
len(food)
[79]:
7
[119]:
# upper case letter
food.upper()
[119]:
'BIRYANI'
[117]:
# lower case letter
food.lower()
[117]:
'biryani'
[115]:
# capatalize every letter
food.capitalize()
[115]:
'Biryani'
[113]:
# replace the letter
food.replace("b","sh")
[113]:
'shiryani'
[105]:
lover="asad and fareeha"
lover
[105]:
'asad and fareeha'
[107]:
lover.capitalize()
[107]:
'Asad and fareeha'
[109]:
lover.lower()
[109]:
'asad and fareeha'
[111]:
lover.replace("asad","fareeha")
[111]:
'fareeha and fareeha'
[125]:
# counting the specific alpahbet in the string
name="asad with fareeha and fareeha with asad"
name
[125]:
'asad with fareeha and fareeha with asad'
[123]:
name.count("a")
[123]:
9
[127]:
name.count("f")
[127]:
2
[129]:
name.count("i")
[129]:
2
# -finding the index number in the string
-finding the index number in the string¶
[132]:
attraction="asad has the attraction for the fareeha"
attraction
[132]:
'asad has the attraction for the fareeha'
[134]:
attraction.find("a")
[134]:
0
[136]:
attraction.find("tt")
[136]:
14
# -split the string
-split the string¶
[144]:
piyar="asad fareeha say mohbat karta ha"
piyar
[144]:
'asad fareeha say mohbat karta ha'
[146]:
piyar.split("a")
[146]:
['', 's', 'd f', 'reeh', ' s', 'y mohb', 't k', 'rt', ' h', '']
[148]:
piyar.split("e")
[148]:
['asad far', '', 'ha say mohbat karta ha']
## 1- tuple
- ordered collection of elements
- enclosed in the () round braces
- different kinds of elemnt can be stored
- onece element can store you can not change them
1- tuple¶
- ordered collection of elements
- enclosed in the () round braces
- different kinds of elemnt can be stored
- onece element can store you can not change them
[172]:
tup1= (1, "python", True, 2.5)
tup1
[172]:
(1, 'python', True, 2.5)
[174]:
tup=(12,45.5,"hello")
tup
[174]:
(12, 45.5, 'hello')
[176]:
tup2=("fari is mine","i love her too much",143)
tup2
[176]:
('fari is mine', 'i love her too much', 143)[178]:
#type of tuple
type(tup)
[178]:
tuple
[182]:
type(tup2)
[182]:
tuple
[184]:
type(tup1)
[184]:
tuple
### -indexing in python
-indexing in python¶
[191]:
tup[1]
[191]:
45.5
[193]:
tup[2]
[193]:
'hello'
[195]:
tup1[1]
[195]:
'python'
[197]:
tup2[1]
[197]:
'i love her too much'
[200]:
tup2[0]
[200]:
'fari is mine'
[202]:
tup1[0:5]
[202]:
(1, 'python', True, 2.5)
[204]:
tup[0:2]
[204]:
(12, 45.5)
[208]:
# last elemnt is exculsive
tup2[0:3]
[208]:
('fari is mine', 'i love her too much', 143)[210]:
#counts of element in tuple
len(tup2)
[210]:
3
[212]:
len(tup1)
[212]:
4
[214]:
len(tup)
[214]:
3
[220]:
# adding of the tuple
tup + tup1 + tup2
[220]:
(12, 45.5, 'hello', 1, 'python', True, 2.5, 'fari is mine', 'i love her too much', 143)
[242]:
# in this we add and repeat the tuple
tup*2 + tup2
[242]:
(12, 45.5, 'hello', 12, 45.5, 'hello', 'fari is mine', 'i love her too much', 143)
[222]:
# minimum value of the tuple
tup3=(10,20,30,40,50,60,70)
tup3
[222]:
(10, 20, 30, 40, 50, 60, 70)
[224]:
min(tup3)
[224]:
10
[230]:
tup4=(33,44,55,66,77,88,99,00)
tup4
[230]:
(33, 44, 55, 66, 77, 88, 99, 0)
[232]:
min(tup4)
[232]:
0
[234]:
# to find the maximum value in the tuple
tup5=(23,34,56,78,99)
tup5
[234]:
(23, 34, 56, 78, 99)
[236]:
max(tup5)
[236]:
99
[238]:
tup6=(88,98,76,44,22)
tup6
[238]:
(88, 98, 76, 44, 22)
[240]:
max(tup6)
[240]:
98
---
# 02 list
- ordered collection of elements
- enclosed in the [] square brackets
- you can change the value
02 list¶
- ordered collection of elements
- enclosed in the [] square brackets
- you can change the value
[247]:
list1=[1,"asad",False]
list
[247]:
list
[249]:
list2=[2,"fareeha",True]
list2
[249]:
[2, 'fareeha', True]
[255]:
#type of list
type(list1)
[255]:
list
[253]:
type(list2)
[253]:
list
[257]:
#adding of list
list1+list2
[257]:
[1, 'asad', False, 2, 'fareeha', True]
[259]:
#adding and reapeting of list
list1*2 + list2
[259]:
[1, 'asad', False, 1, 'asad', False, 2, 'fareeha', True]
[265]:
#to find the length of the list
len(list1)
[265]:
3
[267]:
len(list2)
[267]:
3
[271]:
#indexing is going here
list1[1]
[271]:
'asad'
[273]:
list1[2]
[273]:
False
[277]:
list2[1]
[277]:
'fareeha'
[299]:
#reverse function
list1.reverse()
list1
[299]:
[1, 'asad', False]
[285]:
list2.reverse()
list2
[285]:
[True, 'fareeha', 2]
[287]:
#clear function
list2.clear()
list2
[287]:
[]
[297]:
#copy function
list1.copy()
list1
[297]:
[False, 'asad', 1]
[291]:
list3=[12,90,65,78,34,13,55]
list3
[291]:
[12, 90, 65, 78, 34, 13, 55]
[295]:
#sort function
list3.sort()
list3
[295]:
[12, 13, 34, 55, 65, 78, 90]
[305]:
#this function is attact strings or variavles
list1.append("i want to spent my whole life with fari")
list1
[305]:
[1, 'asad', False, 'i want to spent my whole life with fari', 'i want to spent my whole life with fari', 'i want to spent my whole life with fari']
[317]:
#count function in the string
list1.count("asad")
[317]:
1
[319]:
#to find the length of list
len(list3)
[319]:
7
[323]:
#we can repeat the list
list3*2 + list1
[323]:
[12, 13, 34, 55, 65, 78, 90, 12, 13, 34, 55, 65, 78, 90, 1, 'asad', False, 'i want to spent my whole life with fari', 'i want to spent my whole life with fari', 'i want to spent my whole life with fari']
[325]:
list=list1+list2
list
[325]:
[1, 'asad', False, 'i want to spent my whole life with fari', 'i want to spent my whole life with fari', 'i want to spent my whole life with fari']
[ ]:
[333]:
list4=["asad", "with"]
list4
[333]:
['asad', 'with']
[337]:
list5=["fari"]
list5
[337]:
['fari']
[339]:
list6= list4+list5
list6
[339]:
['asad', 'with', 'fari']
## -dictionaries
- unordered collection of elements
- keys and values
- enclosed in the curly{} brackets
- you can change the value
-dictionaries¶
- unordered collection of elements
- keys and values
- enclosed in the curly{} brackets
- you can change the value
[349]:
# food and their prices
food1={"samosa":30,"pakora":40,"raita":50,"salad":30,"chicken rolls":20}
food1
[349]:
{'samosa': 30, 'pakora': 40, 'raita': 50, 'salad': 30, 'chicken rolls': 20}[369]:
#type of food variable
type(food1)
[369]:
dict
[367]:
#length of food variable
len(food1)
[367]:
5
[373]:
#separate function of key
keys=food1.keys()
keys
[373]:
dict_keys(['samosa', 'pakora', 'raita', 'salad', 'chicken rolls'])
[375]:
#separate function of value
values=food1.values()
values
[375]:
dict_values([30, 40, 50, 30, 20])
[383]:
#adding the new element in the dictionaries
food1["tikki"]=10
food1
[383]:
{'samosa': 30,
'pakora': 40,
'raita': 50,
'salad': 30,
'chicken rolls': 20,
'tikki': 10,
'ice': 10,
'dahibhali': 100}[379]:
food1["ice"]=10
food1
[379]:
{'samosa': 30,
'pakora': 40,
'raita': 50,
'salad': 30,
'chicken rolls': 20,
'tikki': 10,
'ice': 10}[381]:
food1["dahibhali"]=100
food1
[381]:
{'samosa': 30,
'pakora': 40,
'raita': 50,
'salad': 30,
'chicken rolls': 20,
'tikki': 10,
'ice': 10,
'dahibhali': 100}[387]:
#updating the value
food1["ice"]=15
food1
[387]:
{'samosa': 30,
'pakora': 40,
'raita': 50,
'salad': 30,
'chicken rolls': 20,
'tikki': 10,
'ice': 15,
'dahibhali': 100}[391]:
food2={"dates":200,"chocalates":300,"sawanya":500}
food2
[391]:
{'dates': 200, 'chocalates': 300, 'sawanya': 500}[395]:
#adding the both list of food
food1.update(food2)
food1
[395]:
{'samosa': 30,
'pakora': 40,
'raita': 50,
'salad': 30,
'chicken rolls': 20,
'tikki': 10,
'ice': 15,
'dahibhali': 100,
'dates': 200,
'chocalates': 300,
'sawanya': 500}# -set
- unordered and unindexed
- curly braces{} are used
- no duplicate is allowed
-set¶
- unordered and unindexed
- curly braces{} are used
- no duplicate is allowed
[398]:
s1={1,5.5,"asad","fareeha",True}
s1
[398]:
{1, 5.5, 'asad', 'fareeha'}[404]:
#this is the add function and boolen words are not copied in the set
s1.add("lover")
s1
[404]:
{1, 5.5, 'asad', 'fareeha', 'lover'}[406]:
s1.clear()
s1
[406]:
set()
[416]:
s1.update("fareeha","ali")
s1
[416]:
{'a', 'e', 'f', 'h', 'i', 'l', 'r'} Kernel status: Idle
[3]:
# import the libararies\
import seaborn as sns
import matplotlib.pyplot as plt
# load the data set
phool = sns.load_dataset("iris")
phool
[3]:
| sepal_length | sepal_width | petal_length | petal_width | species | |
|---|---|---|---|---|---|
| 0 | 5.1 | 3.5 | 1.4 | 0.2 | setosa |
| 1 | 4.9 | 3.0 | 1.4 | 0.2 | setosa |
| 2 | 4.7 | 3.2 | 1.3 | 0.2 | setosa |
| 3 | 4.6 | 3.1 | 1.5 | 0.2 | setosa |
| 4 | 5.0 | 3.6 | 1.4 | 0.2 | setosa |
| ... | ... | ... | ... | ... | ... |
| 145 | 6.7 | 3.0 | 5.2 | 2.3 | virginica |
| 146 | 6.3 | 2.5 | 5.0 | 1.9 | virginica |
| 147 | 6.5 | 3.0 | 5.2 | 2.0 | virginica |
| 148 | 6.2 | 3.4 | 5.4 | 2.3 | virginica |
| 149 | 5.9 | 3.0 | 5.1 | 1.8 | virginica |
150 rows × 5 columns
[33]:
# import the libararies\
import seaborn as sns
import matplotlib.pyplot as plt
# load the data set
phool = sns.load_dataset("iris")
phool
# draw the bar plot with the color
sns.barplot(x="species" , y="petal_length" ,hue="sepal_length", data=phool )
plt.show()
[21]:
# now we replace the y with sepal_width
# import the libararies\
import seaborn as sns
import matplotlib.pyplot as plt
# load the data set
phool = sns.load_dataset("iris")
phool
# draw the bar plot
sns.barplot(x="species" , y="sepal_width" , data=phool )
plt.show()
[15]:
# for the grouping and now we using the data set of the titanic
[17]:
# this is code is used to check what is in the data set like(titanic)
# import the libararies\
import seaborn as sns
import matplotlib.pyplot as plt
# load the data set
kashti = sns.load_dataset("titanic")
kashti
[17]:
| survived | pclass | sex | age | sibsp | parch | fare | embarked | class | who | adult_male | deck | embark_town | alive | alone | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 3 | male | 22.0 | 1 | 0 | 7.2500 | S | Third | man | True | NaN | Southampton | no | False |
| 1 | 1 | 1 | female | 38.0 | 1 | 0 | 71.2833 | C | First | woman | False | C | Cherbourg | yes | False |
| 2 | 1 | 3 | female | 26.0 | 0 | 0 | 7.9250 | S | Third | woman | False | NaN | Southampton | yes | True |
| 3 | 1 | 1 | female | 35.0 | 1 | 0 | 53.1000 | S | First | woman | False | C | Southampton | yes | False |
| 4 | 0 | 3 | male | 35.0 | 0 | 0 | 8.0500 | S | Third | man | True | NaN | Southampton | no | True |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 886 | 0 | 2 | male | 27.0 | 0 | 0 | 13.0000 | S | Second | man | True | NaN | Southampton | no | True |
| 887 | 1 | 1 | female | 19.0 | 0 | 0 | 30.0000 | S | First | woman | False | B | Southampton | yes | True |
| 888 | 0 | 3 | female | NaN | 1 | 2 | 23.4500 | S | Third | woman | False | NaN | Southampton | no | False |
| 889 | 1 | 1 | male | 26.0 | 0 | 0 | 30.0000 | C | First | man | True | C | Cherbourg | yes | True |
| 890 | 0 | 3 | male | 32.0 | 0 | 0 | 7.7500 | Q | Third | man | True | NaN | Queenstown | no | True |
891 rows × 15 columns
[35]:
# import the libararies\
import seaborn as sns
import matplotlib.pyplot as plt
# load the data set
kashti = sns.load_dataset("titanic")
kashti
# draw the bar plot
sns.barplot(x="who" , y="alone" ,hue="deck", data=kashti )
plt.show()
[37]:
#now we set the order
[45]:
# this is code is used to check what is in the data set like(titanic)
# import the libararies\
import seaborn as sns
import matplotlib.pyplot as plt
# load the data set
kashti = sns.load_dataset("titanic")
kashti
# draw the bar plot and set the order
sns.barplot(x="who" , y="alone" ,hue="deck", data=kashti , order=[ "child","man","woman"] )
plt.show()
[47]:
# now we used the coloring
[59]:
# import the libararies\
import seaborn as sns
import matplotlib.pyplot as plt
# load the data set
kashti = sns.load_dataset("titanic")
kashti
# draw the bar plot
sns.barplot(x="who" , y="alone" ,hue="sex", data=kashti ,order=["woman","child","man"], color="darkgrey" )
plt.show()
C:\Users\Rana Azam\AppData\Local\Temp\ipykernel_14116\127388509.py:11: FutureWarning: Setting a gradient palette using color= is deprecated and will be removed in v0.14.0. Set `palette='dark:darkgrey'` for the same effect. sns.barplot(x="who" , y="alone" ,hue="sex", data=kashti ,order=["woman","child","man"], color="darkgrey" )
[61]:
# now we remove the bar in the plot
[63]:
# this is code is used to check what is in the data set like(titanic)
# import the libararies\
import seaborn as sns
import matplotlib.pyplot as plt
# load the data set
kashti = sns.load_dataset("titanic")
kashti
# draw the bar plot and remove the black bar from the plot by using the confidence interval
sns.barplot(x="who" , y="alone" ,hue="deck", data=kashti , order=[ "child","man","woman"], ci=None )
plt.show()
C:\Users\Rana Azam\AppData\Local\Temp\ipykernel_14116\2431501591.py:11: FutureWarning: The `ci` parameter is deprecated. Use `errorbar=None` for the same effect. sns.barplot(x="who" , y="alone" ,hue="deck", data=kashti , order=[ "child","man","woman"], ci=None )
[65]:
# now we used the different types of palette
[67]:
# this is code is used to check what is in the data set like(titanic)
# import the libararies\
import seaborn as sns
import matplotlib.pyplot as plt
# load the data set
kashti = sns.load_dataset("titanic")
kashti
# draw the bar plot and set the order
sns.barplot(x="who" , y="alone" ,hue="deck", data=kashti , order=[ "child","man","woman"],ci=None,
palette="pastel")
plt.show()
C:\Users\Rana Azam\AppData\Local\Temp\ipykernel_14116\2145264662.py:11: FutureWarning: The `ci` parameter is deprecated. Use `errorbar=None` for the same effect. sns.barplot(x="who" , y="alone" ,hue="deck", data=kashti , order=[ "child","man","woman"],ci=None,
[69]:
# for the estimator we import the librarie of the numpy
[77]:
# import the libararies\
import seaborn as sns
from numpy import median
import matplotlib.pyplot as plt
# load the data set
kashti = sns.load_dataset("titanic")
kashti
# draw the bar plot and set the order
sns.barplot(x="who" , y="fare" ,hue="deck", data=kashti , order=[ "child","man","woman"] , estimator=median,ci=None,palette="pastel")
plt.show()
C:\Users\Rana Azam\AppData\Local\Temp\ipykernel_14116\2451678822.py:11: FutureWarning: The `ci` parameter is deprecated. Use `errorbar=None` for the same effect. sns.barplot(x="who" , y="fare" ,hue="deck", data=kashti , order=[ "child","man","woman"] , estimator=median,ci=None,palette="pastel")
[79]:
# for the color intensity we also used the saturation
[89]:
# import the libararies\
import seaborn as sns
from numpy import median
import matplotlib.pyplot as plt
# load the data set
kashti = sns.load_dataset("titanic")
kashti
# draw the bar plot and set the saturation intensity of the color
sns.barplot(x="who" , y="fare" ,hue="deck", data=kashti , order=[ "child","man","woman"] , estimator=median,ci=None,
saturation=1)
plt.show()
C:\Users\Rana Azam\AppData\Local\Temp\ipykernel_14116\2056478644.py:11: FutureWarning: The `ci` parameter is deprecated. Use `errorbar=None` for the same effect. sns.barplot(x="who" , y="fare" ,hue="deck", data=kashti , order=[ "child","man","woman"] , estimator=median,ci=None,
# set the style
- this is for the line plot
set the style¶
- this is for the line plot
[102]:
import seaborn as sns
import matplotlib.pyplot as plt
phool=sns.load_dataset("iris")
sns.lineplot(x="sepal_length",y="species",data=phool)
sns.set_style("darkgrid")
[106]:
# now we form the horizantal plot
[108]:
# import the libararies\
import seaborn as sns
from numpy import median
import matplotlib.pyplot as plt
# load the data set
kashti = sns.load_dataset("titanic")
kashti
# draw the bar plot and set numeric value on the x axis and categorical value on the y axis
sns.barplot(x="fare" , y="who" ,hue="deck", data=kashti , order=[ "child","man","woman"] , estimator=median,ci=None,
saturation=1)
plt.show()
C:\Users\Rana Azam\AppData\Local\Temp\ipykernel_14116\122115732.py:11: FutureWarning: The `ci` parameter is deprecated. Use `errorbar=None` for the same effect. sns.barplot(x="fare" , y="who" ,hue="deck", data=kashti , order=[ "child","man","woman"] , estimator=median,ci=None,
[140]:
# import the libararies\
import seaborn as sns
import matplotlib.pyplot as plt
# load the data set
kashti = sns.load_dataset("titanic")
kashti
# draw the bar plot and set numeric value on the x axis and categorical value on the y axis
sns.barplot(x="class" , y="fare" ,hue="deck", data=kashti ,
linewidth=5,facecolor=(.6,.7,.8,.9),
errcolor="0",edgecolor="0.3")
sns.set_style("white")
plt.show()
C:\Users\Rana Azam\AppData\Local\Temp\ipykernel_14116\756062696.py:10: FutureWarning:
The `errcolor` parameter is deprecated. And will be removed in v0.15.0. Pass `err_kws={'color': '0'}` instead.
sns.barplot(x="class" , y="fare" ,hue="deck", data=kashti ,
Kernel status: Idle
[12]:
# import the libraray
import seaborn as sns
# set the style
sns.set_style("whitegrid")
#load the data set
kashti = sns.load_dataset("titanic")
# darw the box plot
sns.boxplot(x="class", y="fare" ,color="red",data=kashti)
[12]:
<Axes: xlabel='class', ylabel='fare'>
[14]:
# for another data set
[18]:
# this code is used for the to check what is in the data set
# import the libraray
import seaborn as sns
# set the style
sns.set_style("whitegrid")
#load the data set
tip = sns.load_dataset("tips")
tip
[18]:
| total_bill | tip | sex | smoker | day | time | size | |
|---|---|---|---|---|---|---|---|
| 0 | 16.99 | 1.01 | Female | No | Sun | Dinner | 2 |
| 1 | 10.34 | 1.66 | Male | No | Sun | Dinner | 3 |
| 2 | 21.01 | 3.50 | Male | No | Sun | Dinner | 3 |
| 3 | 23.68 | 3.31 | Male | No | Sun | Dinner | 2 |
| 4 | 24.59 | 3.61 | Female | No | Sun | Dinner | 4 |
| ... | ... | ... | ... | ... | ... | ... | ... |
| 239 | 29.03 | 5.92 | Male | No | Sat | Dinner | 3 |
| 240 | 27.18 | 2.00 | Female | Yes | Sat | Dinner | 2 |
| 241 | 22.67 | 2.00 | Male | Yes | Sat | Dinner | 2 |
| 242 | 17.82 | 1.75 | Male | No | Sat | Dinner | 2 |
| 243 | 18.78 | 3.00 | Female | No | Thur | Dinner | 2 |
244 rows × 7 columns
[20]:
# import the libraray
import seaborn as sns
# set the style
sns.set_style("whitegrid")
#load the data set
tip = sns.load_dataset("tips")
tip
# darw the box plot
sns.boxplot(x="day", y="tip" ,color="red",data=tip)
[20]:
<Axes: xlabel='day', ylabel='tip'>
[30]:
# now we see that argument we used in the barplots are we used the arguments in the boxplot box plot also
# tells us about the avearge in which mean and emdian is not required
[28]:
# import the libraray
import seaborn as sns
# set the style
sns.set_style("whitegrid")
#load the data set
tip = sns.load_dataset("tips")
tip
# darw the box plot we used the argument of the barplot in the box plot
sns.boxplot(x="day", y="tip" ,color="red",data=tip,saturation=0.1)
[28]:
<Axes: xlabel='day', ylabel='tip'>
[32]:
# now we know about the function of the details which is used to describe the data set in details
[48]:
# import linraries
import seaborn as sns
import pandas as pf
import numpy as np
# load the data set
tip = sns.load_dataset("tips")
# to decribe the data set which is used in the data set we draw the numeric variable on the y axis and the categorical variable on the x axis
tip.describe
[48]:
<bound method NDFrame.describe of total_bill tip sex smoker day time size 0 16.99 1.01 Female No Sun Dinner 2 1 10.34 1.66 Male No Sun Dinner 3 2 21.01 3.50 Male No Sun Dinner 3 3 23.68 3.31 Male No Sun Dinner 2 4 24.59 3.61 Female No Sun Dinner 4 .. ... ... ... ... ... ... ... 239 29.03 5.92 Male No Sat Dinner 3 240 27.18 2.00 Female Yes Sat Dinner 2 241 22.67 2.00 Male Yes Sat Dinner 2 242 17.82 1.75 Male No Sat Dinner 2 243 18.78 3.00 Female No Thur Dinner 2 [244 rows x 7 columns]>
[56]:
# this function is used to decribe the numeric values and their averages and we canot take the numeric values in the hue
tip.describe()
[56]:
| total_bill | tip | size | |
|---|---|---|---|
| count | 244.000000 | 244.000000 | 244.000000 |
| mean | 19.785943 | 2.998279 | 2.569672 |
| std | 8.902412 | 1.383638 | 0.951100 |
| min | 3.070000 | 1.000000 | 1.000000 |
| 25% | 13.347500 | 2.000000 | 2.000000 |
| 50% | 17.795000 | 2.900000 | 2.000000 |
| 75% | 24.127500 | 3.562500 | 3.000000 |
| max | 50.810000 | 10.000000 | 6.000000 |
[58]:
# now we draw the plot for only the single value
[68]:
# import the libraray
import seaborn as sns
# set the style
sns.set_style("whitegrid")
#load the data set
tip = sns.load_dataset("tips")
tip
# darw the box plot we used the argument of the barplot in the box plot
sns.boxplot(y=tip["total_bill"])
[68]:
<Axes: ylabel='total_bill'>
[70]:
# now darw the boxplot according to the days
[78]:
# import the libraray
import seaborn as sns
# set the style
sns.set_style("whitegrid")
#load the data set
tip = sns.load_dataset("tips")
tip
# darw the box plot and we add the hue
sns.boxplot(x="tip" , y="day",hue="smoker", data=tip)
[78]:
<Axes: xlabel='tip', ylabel='day'>
[80]:
# we add some argument in the draw the box plot
[90]:
# import the libraray
import seaborn as sns
# set the style
sns.set_style("whitegrid")
#load the data set
tip = sns.load_dataset("tips")
tip
# darw the box plot and we add the hue and dodge is the argument in which boolen language is used
sns.boxplot(x="tip" , y="day",hue="smoker",
palette="Set2", data=tip , dodge=False)
[90]:
<Axes: xlabel='tip', ylabel='day'>
[94]:
# now we add the arguments of the color in the draw_boxplot
[106]:
# import the libraray
import seaborn as sns
# set the style
sns.set_style("whitegrid")
#load the data set
tip = sns.load_dataset("tips")
tip
# darw the box plot and we add the color by using hex color picker website
sns.boxplot(x="tip" , y="day",color="#917f4c",
data=tip )
[106]:
<Axes: xlabel='tip', ylabel='day'>
[114]:
# now we draw the function in which shows the just first five line of the data set
[112]:
import seaborn as sns
import pandas as pd
import numpy as np
kashti=sns.load_dataset("titanic")
kashti.head()
[112]:
| survived | pclass | sex | age | sibsp | parch | fare | embarked | class | who | adult_male | deck | embark_town | alive | alone | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 3 | male | 22.0 | 1 | 0 | 7.2500 | S | Third | man | True | NaN | Southampton | no | False |
| 1 | 1 | 1 | female | 38.0 | 1 | 0 | 71.2833 | C | First | woman | False | C | Cherbourg | yes | False |
| 2 | 1 | 3 | female | 26.0 | 0 | 0 | 7.9250 | S | Third | woman | False | NaN | Southampton | yes | True |
| 3 | 1 | 1 | female | 35.0 | 1 | 0 | 53.1000 | S | First | woman | False | C | Southampton | yes | False |
| 4 | 0 | 3 | male | 35.0 | 0 | 0 | 8.0500 | S | Third | man | True | NaN | Southampton | no | True |
[141]:
import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
kashti=sns.load_dataset("titanic")
kashti.head()
sns.boxplot(x="survived",
y="age",
data=kashti)
[141]:
<Axes: xlabel='survived', ylabel='age'>
[122]:
# now we hightlight the mean by adding the arguments in the draw box plot
[124]:
sns.boxplot(x="survived",
y="age",showmeans=True,
data=kashti)
[124]:
<Axes: xlabel='survived', ylabel='age'>
[127]:
# now we making the highlight to the sign of the mean
[135]:
sns.boxplot(x="survived",
y="age",showmeans=True,
meanprops={"marker":"^",
"markersize":"12",
"markeredgecolor":"black"},
data=kashti)
[135]:
<Axes: xlabel='survived', ylabel='age'>
[137]:
# now we add the labels in the plot and the design them
[163]:
import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
sns.boxplot(x="survived",
y="age",showmeans=True,
meanprops={"marker":"^",
"markersize":"12",
"markeredgecolor":"black"},
data=kashti)
# show the labels
plt.xlabel("how many survied"),
plt.ylabel("Age (years)"),
plt.title("box_plot")
[163]:
Text(0.5, 1.0, 'box_plot')
[165]:
# now we add the labels in the plot and the design them and we also change their size
[169]:
import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
sns.boxplot(x="survived",
y="age",showmeans=True,
meanprops={"marker":"^",
"markersize":"12",
"markeredgecolor":"black"},
data=kashti)
# show the labels
plt.xlabel("how many survied",size=12),
plt.ylabel("Age (years)",size=12),
plt.title("box_plot",size=11)
[169]:
Text(0.5, 1.0, 'box_plot')
[171]:
# now we add the labels in the plot and the design them and we also change their size and also we bold the titels or labels
[181]:
import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
sns.boxplot(x="survived",
y="age",showmeans=True,
meanprops={"marker":"^",
"markersize":"12",
"markeredgecolor":"black"},
data=kashti)
# show the labels
plt.xlabel("how many survied",size=12,weight="bold"),
plt.ylabel("Age (years)",size=12,weight="bold"),
plt.title("box_plot",size=11,weight="bold")
[181]:
Text(0.5, 1.0, 'box_plot')
- test_jupyter_notebook
- indexing and data structure
- 02_bar_plot
- 03_boxplot
- 04_otherplots
- 05_interactive
- 06_array
Kernel status: Idle Executed 3 cellsElapsed time: 7 seconds
# lineplot_withmultifacet
- and we found these plots from the seaborn website
lineplot_withmultifacet¶
- and we found these plots from the seaborn website
[3]:
# time series plot
[9]:
import seaborn as sns
sns.set_theme(style="darkgrid")
# Load an example dataset with long-form data
fmri = sns.load_dataset("fmri")
fmri.head()
[9]:
| subject | timepoint | event | region | signal | |
|---|---|---|---|---|---|
| 0 | s13 | 18 | stim | parietal | -0.017552 |
| 1 | s5 | 14 | stim | parietal | -0.080883 |
| 2 | s12 | 18 | stim | parietal | -0.081033 |
| 3 | s11 | 18 | stim | parietal | -0.046134 |
| 4 | s10 | 18 | stim | parietal | -0.037970 |
[5]:
import seaborn as sns
sns.set_theme(style="darkgrid")
# Load an example dataset with long-form data
fmri = sns.load_dataset("fmri")
# Plot the responses for different events and regions
sns.lineplot(x="timepoint", y="signal",
hue="region", style="event",
data=fmri)
[5]:
<Axes: xlabel='timepoint', ylabel='signal'>
[11]:
# line plot on multiple facts
[13]:
import seaborn as sns
sns.set_theme(style="ticks")
dots = sns.load_dataset("dots")
dots.head()
[13]:
| align | choice | time | coherence | firing_rate | |
|---|---|---|---|---|---|
| 0 | dots | T1 | -80 | 0.0 | 33.189967 |
| 1 | dots | T1 | -80 | 3.2 | 31.691726 |
| 2 | dots | T1 | -80 | 6.4 | 34.279840 |
| 3 | dots | T1 | -80 | 12.8 | 32.631874 |
| 4 | dots | T1 | -80 | 25.6 | 35.060487 |
[15]:
# Define the palette as a list to specify exact values
palette = sns.color_palette("rocket_r")
# Plot the lines on two facets
sns.relplot(
data=dots,
x="time", y="firing_rate",
hue="coherence", size="choice", col="align",
kind="line", size_order=["T1", "T2"], palette=palette,
height=5, aspect=.75, facet_kws=dict(sharex=False),
)
[15]:
<seaborn.axisgrid.FacetGrid at 0x1f42cc07770>
Kernel status: Idle Executed 4 cellsElapsed time: 6 seconds
[1]:
pip install plotly
Requirement already satisfied: plotly in c:\users\rana azam\anaconda3\asad\lib\site-packages (5.22.0) Requirement already satisfied: tenacity>=6.2.0 in c:\users\rana azam\anaconda3\asad\lib\site-packages (from plotly) (8.2.2) Requirement already satisfied: packaging in c:\users\rana azam\anaconda3\asad\lib\site-packages (from plotly) (23.2) Note: you may need to restart the kernel to use updated packages.
[17]:
# by installing the pip plotly we can form intractive plot one of the example is given below
[9]:
import plotly.express as px
phool = px.data.iris()
phool.head()
[9]:
| sepal_length | sepal_width | petal_length | petal_width | species | species_id | |
|---|---|---|---|---|---|---|
| 0 | 5.1 | 3.5 | 1.4 | 0.2 | setosa | 1 |
| 1 | 4.9 | 3.0 | 1.4 | 0.2 | setosa | 1 |
| 2 | 4.7 | 3.2 | 1.3 | 0.2 | setosa | 1 |
| 3 | 4.6 | 3.1 | 1.5 | 0.2 | setosa | 1 |
| 4 | 5.0 | 3.6 | 1.4 | 0.2 | setosa | 1 |
Kernel status: Idle
# 1D array
- we can aslo called the vector to the 1D array
1D array¶
- we can aslo called the vector to the 1D array
[6]:
# import the libraray
import numpy as np
a= np.array([5,5,5])
a
[6]:
array([5, 5, 5])
[8]:
# to find the type of the array
[10]:
type(a)
[10]:
numpy.ndarray
[12]:
# to find the length of the array
[14]:
len(a)
[14]:
3
[16]:
# now wwe done the indexing the array or location of the element
[18]:
a[0]
[18]:
5
[20]:
# we can also take the output by doing the given below action
[24]:
a[0:4]
[24]:
array([5, 5, 5])
[46]:
# now we create there some types of the array
[62]:
# these are the examples of 1D array
[48]:
import numpy as np
a = np.array([1,2,3,4,5])
a
[48]:
array([1, 2, 3, 4, 5])
[52]:
# when we want the zeros in the array then we done this type of the code
[56]:
b = np.zeros(2)
b
[56]:
array([0., 0.])
[58]:
# when we want the ones in the array then we done this type of the code
[60]:
c = np.ones(5)
c
[60]:
array([1., 1., 1., 1., 1.])
[66]:
# we can create also the empty array with 3 elemnts or more
[74]:
d = np.empty(1)
d
[74]:
array([2.4e-322])
[80]:
# we can also create the array by given the range
[78]:
e = np.arange(6)
e
[78]:
array([0, 1, 2, 3, 4, 5])
[82]:
# we can also create the array by given the specific range(from this to this)
[86]:
f = np.arange(2,15)
f
[86]:
array([ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])
[88]:
# we can also create the array by give the specific number and thier difference
[92]:
g = np.arange(2,20,2)
g
[92]:
array([ 2, 4, 6, 8, 10, 12, 14, 16, 18])
[94]:
# we can also create linerly spaced arraya
[100]:
h = np.linspace(0,10,num=5) # give use 5 nums
h
[100]:
array([ 0. , 2.5, 5. , 7.5, 10. ])
[102]:
# we use the array to obtain the output in specific data by using the this formula
[104]:
i = np.ones(5, dtype=np.int8)
i
[104]:
array([1, 1, 1, 1, 1], dtype=int8)
[108]:
i = np.ones(3, dtype=np.float64)
i
[108]:
array([1., 1., 1.])
# 2D array
- we can also called the matrices to the 2D array
2D array¶
- we can also called the matrices to the 2D array
[115]:
import numpy as np
b = np.array([[5, 5, 5],[5, 5, 5],[5, 5, 5]])
b
[115]:
array([[5, 5, 5],
[5, 5, 5],
[5, 5, 5]])[117]:
type(b)
[117]:
numpy.ndarray
[119]:
len(b)
[119]:
3
[123]:
# indexing of the array
[121]:
b[0]
[121]:
array([5, 5, 5])
[125]:
b[0:]
[125]:
array([[5, 5, 5],
[5, 5, 5],
[5, 5, 5]])[127]:
b[0:3]
[127]:
array([[5, 5, 5],
[5, 5, 5],
[5, 5, 5]])# in 2D array when we talk about the axis first we include the column and then row e.g(2,4) in this 2 is the column and 4 is the row
in 2D array when we talk about the axis first we include the column and then row e.g(2,4) in this 2 is the column and 4 is the row¶
[130]:
np.zeros((3,4)) # 3 means rows and 4 mean columns
[130]:
array([[0., 0., 0., 0.],
[0., 0., 0., 0.],
[0., 0., 0., 0.]])[134]:
np.ones((6,5))
[134]:
array([[1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1.]])[136]:
np.empty((3,4))
[136]:
array([[0., 0., 0., 0.],
[0., 0., 0., 0.],
[0., 0., 0., 0.]])# 3D array
3D array¶
[149]:
i = np.arange(24).reshape(2,3,4) # in which 2 is number of the matrices and 3 is coimuns and 4 is the rows
i
[149]:
array([[[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]],
[[12, 13, 14, 15],
[16, 17, 18, 19],
[20, 21, 22, 23]]])Common Tools
No metadata.
Advanced Tools
No metadata.
Anaconda Assistant
AI-powered coding, insights and debugging in your notebooks.
To enable the following extensions, create an account or sign in.
- Anaconda Assistant4.0.15
- Coming soon!
- Data Catalogs
- Panel Deployments
- Sharing
Already have an account? Sign In
For more information, read our Anaconda Assistant documentation.